package main

import "fmt"

// dump slice length, capacity, and contents
func dump(label string, slice []string) {
	fmt.Printf("%v: length %v, capacity %v %v\n", label, len(slice), cap(slice), slice)
}

// 三个索引的切分操作
// 限制新建切片容量
func main() {
	planets := []string{
		"Mercury", "Venus", "Earth", "Mars",
		"Jupiter", "Saturn", "Uranus", "Neptune",
	}
	fmt.Println("planets:", planets) //原始数组

	terrestrial := planets[0:4:5] //容量是5
	terrestrial = append(terrestrial, "1")
	fmt.Println("planets:", planets) //和上次不一样
	dump("terrestrial", terrestrial)

	terrestrial = append(terrestrial, "1") // append超出容量，复制了新数组
	fmt.Println("planets:", planets)       //和上次一样
	dump("terrestrial", terrestrial)

	terrestrial = planets[0:4] // 容量是10
	terrestrial = append(terrestrial, "1", "1", "1")

	fmt.Println("planets:", planets)
	dump("terrestrial", terrestrial)

	_ = terrestrial
}
